package com.hex.ds.hdtp.core.app.script.transfer.service.impl;

import com.hex.ds.hdtp.core.app.common.page.PageData;
import com.hex.ds.hdtp.core.app.common.page.converter.IPageAndPageDtoConverter;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.script.transfer.converter.IScriptConvertOptLogConverter;
import com.hex.ds.hdtp.core.app.script.transfer.dto.request.ScriptConvertOptLogRequestDto;
import com.hex.ds.hdtp.core.app.script.transfer.dto.response.ScriptConvertOptLogResponseDto;
import com.hex.ds.hdtp.core.app.script.transfer.service.IScriptConvertOptLogService;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertOptLogPo;
import com.hex.ds.hdtp.core.inf.script.transfer.repository.IScriptConvertOptLogRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class ScriptConvertOptLogService implements IScriptConvertOptLogService {

    private final IScriptConvertOptLogRepository scriptConvertOptLogRepository;

    private final IPageAndPageDtoConverter pageAndPageDtoConverter;

    private final IScriptConvertOptLogConverter converter;

    private ScriptConvertOptLogPo toScriptConvertListHisPo(ScriptConvertOptLogRequestDto scriptConvertListRequestDto){
        return converter.toScriptConvertListHisPo(scriptConvertListRequestDto);
    }

    @Override
    public ScriptConvertOptLogResponseDto queryById(String pkId) {
        ScriptConvertOptLogPo scriptConvertOptLogPo = scriptConvertOptLogRepository.queryById(pkId);
        return converter.toScriptConvertListHisResponseDto(scriptConvertOptLogPo);
    }

    @Override
    public List<ScriptConvertOptLogResponseDto> queryByScriptConvertListId(String scriptConvertListId) {
        List<ScriptConvertOptLogPo> scriptConvertOptLogPos = scriptConvertOptLogRepository.queryByScriptConvertListId(scriptConvertListId);
        return converter.toScriptConvertListHisResponseDtoList(scriptConvertOptLogPos);
    }

    @Override
    public PageData queryListByPage(ScriptConvertOptLogRequestDto scriptConvertOptLogRequestDto, PageDto pageDto) {
        final Page<ScriptConvertOptLogPo> pageResult = scriptConvertOptLogRepository.queryListByPage(
                toScriptConvertListHisPo(scriptConvertOptLogRequestDto), pageAndPageDtoConverter.toPage(pageDto));
        List<ScriptConvertOptLogResponseDto> responseDtos = converter.toScriptConvertListHisResponseDtoList(pageResult.getData());
        return new PageData(responseDtos, pageResult.getTotal());
    }

    @Override
    public void add(ScriptConvertOptLogRequestDto scriptConvertOptLogRequestDto) {
        int count = scriptConvertOptLogRepository.add(toScriptConvertListHisPo(scriptConvertOptLogRequestDto));
        if (count != 1){

        }
    }

    @Override
    public void modifyById(ScriptConvertOptLogRequestDto scriptConvertOptLogRequestDto) {
        int count = scriptConvertOptLogRepository.modifyById(toScriptConvertListHisPo(scriptConvertOptLogRequestDto));
        if (count != 1){

        }
    }

    @Override
    public void removeById(String pkId) {
        int count = scriptConvertOptLogRepository.removeById(pkId);
        if (count != 1){

        }
    }
}
